import 'package:favorcate/core/model/meal_model.dart';
import 'package:flutter/material.dart';

import 'filter_view_model.dart';

class BaseMealViewModel extends ChangeNotifier {
  List<ZSMealModel> _meals = [];

  late ZSFilterViewModel _filterVM;

  void updateFilters(ZSFilterViewModel filterVM) {
    _filterVM = filterVM;
  }

  List<ZSMealModel> get meals {
    return _meals.where((meal) {
      //过滤
      if (_filterVM.isGlutenFree && !meal.isGlutenFree!) return false;
      if (_filterVM.isLactoseFree && !meal.isLactoseFree!) return false;
      if (_filterVM.isVegetarian && !meal.isVegetarian!) return false;
      if (_filterVM.isVegan && !meal.isVegan!) return false;
      return true;
    }).toList();
  }

  List<ZSMealModel> get originMeals => _meals;

  set meals(List<ZSMealModel> value) {
    _meals = value;
    notifyListeners();
  }
}
